module encode8b10b1(original_in,original_clk,rstn,key1,rd,out);

//定义输入输出端口
input original_clk,rstn;
input [8:0] original_in;
output rd;
output [9:0] out;
input key1;
//指定 端口的类型
wire [8:0] original_in;
wire original_clk,rstn;
wire [7:0] led_drv;
wire [5:0] led_sel;
wire key1,key2,key3;
// 定义中间变量
reg rd_temp;		
reg [7:0] in;		
wire [4:0] in_5b_to_6b;
wire [2:0] in_3b_to_4b;
wire [6:0] out_5b_to_6b;
wire [4:0] out_3b_to_4b;
wire [9:0] out_common;
wire [9:0] out_particular;
wire [9:0] out;
wire [11:0] in12b;
wire rd;
reg k;
wire rd_common;
wire rd_particular;
always@(posedge key1 or negedge rstn)begin
if(!rstn)
	in <= 0;
else
	in <= original_in[7:0];
end

always@(posedge key1 or negedge rstn)begin
if(!rstn)
	k <= 0;
else
	k <= original_in[8];
end

always@(posedge key1 or negedge rstn)begin
if(!rstn)
	rd_temp <= 0;
else
	rd_temp <= rd;
end

assign in12b = {out_3b_to_4b[4:0],out_5b_to_6b[6:0]};
assign in_5b_to_6b = in[4:0];
assign in_3b_to_4b = in[7:5];
assign out = k ? out_particular : out_common;
assign rd = k ? rd_particular:rd_common;

//5b6b默认编码模块
default_encode_5b_to_6b en56(
	.in_5b_to_6b(in_5b_to_6b),
	.out_5b_to_6b(out_5b_to_6b)
	);

//3b4b默认编码模块
default_encode_3b_to_4b en34	(
	.in_3b_to_4b(in_3b_to_4b),
	.out_3b_to_4b(out_3b_to_4b),
	.out_5b_to_6b(out_5b_to_6b)
	);
	
//差异度计算模块	
running_disparity running_disparity(.rd_temp(rd_temp),
	.in12b(in12b),
	.out_common(out_common),
	.rd_common(rd_common)
	);
	
//特殊编码模块
particular particular(
	.in_particular(in),
	.out_particular(out_particular),
	.rd_temp(rd_temp),
	.rd_particular(rd_particular)
	);	

endmodule











